import { Injectable } from '@angular/core';
import { LocalizationService } from '@abp/ng.core';
import { NzModalService } from 'ng-zorro-antd/modal';
import { Observable } from 'rxjs';
import { BillOfMaterialsDto } from '../../proxy/joy/erp/basic-archives/item-masters';
import { BillOfMaterialsRefEntityComponent } from './bill-of-materials-ref-entity.component';

@Injectable({
  providedIn: 'root',
})
export class BillOfMaterialsRefEntityService {
  private defaultTitle: 'BasicArchives::UI:SimplyTree.RefEntity.AddTitle' | 'BasicArchives::UI:SimplyTree.RefEntity.EditTitle' = 'BasicArchives::UI:SimplyTree.RefEntity.AddTitle';
  private defaultWidth: number = 600;
  constructor(private modalService: NzModalService, private localizationService: LocalizationService) {}
  show(model?: BillOfMaterialsDto, options?: { title?: string; width?: number }): Observable<any> {
    var nzTitle = !options?.title ? this.l(this.defaultTitle, this.l('BasicArchives::Menu:BasicArchives.ArchivesManagement.ItemMasters.BillOfMaterials')) : options.title;
    var nzWidth = !options?.width ? this.defaultWidth : options.width;
    let modalRef = this.modalService.create({
      nzTitle: nzTitle,
      nzMaskClosable: false,
      nzKeyboard: true,
      nzWidth: nzWidth,
      nzComponentParams: {
        model: !model ? null : model,
      },
      nzContent: BillOfMaterialsRefEntityComponent,
    });
    return modalRef.afterClose.asObservable();
  }  
  
  protected l(key: string, ...parmas: string[]): string {
    return this.localizationService.instant(key, ...parmas);
  }
}
